function [tst] = kneu_test_rda(R,TEST)
% Friedmann 1989
% coded by Christoph Reichert

p = size(TEST,2);
N = size(TEST,1);
dk=zeros(N,length(R.classes));

for k = 1:length(R.classes),
    sigma = squeeze(R.rda.sigma(k,:,:));
    PIk = R.rda.Wk(k)/sum(R.rda.Wk);
    for s=1:N,
        % discrimination score
        dk(s,k)=(TEST(s,:)-R.rda.mu(k,:))/sigma*(TEST(s,:)-R.rda.mu(k,:))'...
                + log(det(sigma)) - 2*log(PIk); %eq.9
    end
end

tst.likelihoods = 1-dk./(sum(dk,2)*ones(1,size(dk,2)));
[maxScore, maxIdx]=max(tst.likelihoods,[],2);
tst.prediction=R.classes(maxIdx);
